import { CoolController, BaseController } from '@cool-midway/core';
import { DeviceDeviceEntity } from '../../entity/device';
import { DeviceDeviceService } from '../../service/device';
import { Inject } from '@midwayjs/core';
import { TenantAgentEntity } from '../../../tenant/entity/agent';
import { IotCardCardEntity } from '../../../iotCard/entity/card';

/**
 * 设备信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: DeviceDeviceEntity,
  service: DeviceDeviceService,
  pageQueryOp: {
    keyWordLikeFields: ['a.name'],
    fieldEq: ['a.serialNumber', 'a.iccid', 'a.status'],
    select: ['a.*', 'b.name as tenantName'],
    join: [
      {
        entity: TenantAgentEntity,
        alias: 'b',
        condition: 'a.tenantId = b.id',
        type: 'leftJoin',
      },
      /* 还需要返回设备绑定的物联卡信息 */
      {
        entity: IotCardCardEntity,
        alias: 'c',
        condition: 'a.id = c.deviceId',
        type: 'leftJoin',
      },
    ],
  },
})
export class AdminDeviceDeviceController extends BaseController {
  @Inject()
  deviceDeviceService: DeviceDeviceService;
}
